package com.java110.mall.shop.smo.impl;


import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.dto.shop.ShopVisitDto;
import com.java110.intf.shop.IShopVisitInnerServiceSMO;
import com.java110.po.shop.ShopVisitPo;
import com.java110.mall.shop.dao.IShopVisitServiceDao;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 商铺访问内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class ShopVisitInnerServiceSMOImpl extends BaseServiceSMO implements IShopVisitInnerServiceSMO {

    @Autowired
    private IShopVisitServiceDao shopVisitServiceDaoImpl;


    @Override
    public int saveShopVisit(@RequestBody ShopVisitPo shopVisitPo) {
        int saveFlag = 1;
        shopVisitServiceDaoImpl.saveShopVisitInfo(BeanConvertUtil.beanCovertMap(shopVisitPo));
        return saveFlag;
    }

    @Override
    public int updateShopVisit(@RequestBody ShopVisitPo shopVisitPo) {
        int saveFlag = 1;
        shopVisitServiceDaoImpl.updateShopVisitInfo(BeanConvertUtil.beanCovertMap(shopVisitPo));
        return saveFlag;
    }

    @Override
    public int deleteShopVisit(@RequestBody ShopVisitPo shopVisitPo) {
        int saveFlag = 1;
        shopVisitPo.setStatusCd("1");
        shopVisitServiceDaoImpl.updateShopVisitInfo(BeanConvertUtil.beanCovertMap(shopVisitPo));
        return saveFlag;
    }

    @Override
    public List<ShopVisitDto> queryShopVisits(@RequestBody ShopVisitDto shopVisitDto) {

        //校验是否传了 分页信息

        int page = shopVisitDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            shopVisitDto.setPage((page - 1) * shopVisitDto.getRow());
        }

        List<ShopVisitDto> shopVisits = BeanConvertUtil.covertBeanList(shopVisitServiceDaoImpl.getShopVisitInfo(BeanConvertUtil.beanCovertMap(shopVisitDto)), ShopVisitDto.class);

        return shopVisits;
    }


    @Override
    public int queryShopVisitsCount(@RequestBody ShopVisitDto shopVisitDto) {
        return shopVisitServiceDaoImpl.queryShopVisitsCount(BeanConvertUtil.beanCovertMap(shopVisitDto));
    }

    public IShopVisitServiceDao getShopVisitServiceDaoImpl() {
        return shopVisitServiceDaoImpl;
    }

    public void setShopVisitServiceDaoImpl(IShopVisitServiceDao shopVisitServiceDaoImpl) {
        this.shopVisitServiceDaoImpl = shopVisitServiceDaoImpl;
    }
}
